package entity

import "fmt"

type Topic struct {
	ID         int               `gorm:"primaryKey;autoIncrement:true;comment:主键"`
	Subject    string            `gorm:"type:varchar(255);not null;comment:学科"`
	Type       string            `gorm:"type:varchar(255);not null;comment:题目类型"`
	Question   string            `gorm:"type:text;not null;comment:题目内容"`
	Options    map[string]string `gorm:"type:json;serializer:json;not null;comment:选项"`
	Answer     string            `gorm:"type:varchar(255);serializer:json;not null;comment:答案"`
	Difficulty string            `gorm:"type:varchar(255);not null;comment:难度"`
	Knowledge  *string           `gorm:"type:varchar(255);default:null;comment:知识点"`
	Analyze    *string           `gorm:"type:text;comment:解析"`
}

// 自定义表名（可选）
func (Topic) TableName() string {
	return "topic"
}

func (t Topic) ToString() string {
	knowledge := "null"
	if t.Knowledge != nil {
		knowledge = *t.Knowledge
	}

	analyze := "null"
	if t.Analyze != nil {
		analyze = *t.Analyze
	}

	return fmt.Sprintf(
		"Topic{ID=%d, Subject=%s, Type=%s, Question=%s, Options=%v, Answer=%s, Difficulty=%s, Knowledge=%s, Analyze=%s}",
		t.ID,
		t.Subject,
		t.Type,
		t.Question,
		t.Options,
		t.Answer,
		t.Difficulty,
		knowledge,
		analyze,
	)
}
